﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using zUfDsl.ModelUF;

namespace zUfDsl.Common
{
    /// <summary>
    /// 获取数据库连接
    /// </summary>
    internal class HandleDb
    {
        /// <summary>
        /// 更改连接字符串
        /// </summary>
        /// <param name="originalConnStr"></param>
        /// <param name="newCatalog"></param>
        /// <returns></returns>
        private string ModifyCatalog(string originalConnStr, string newCatalog)
        {
            var builder = new System.Data.SqlClient.SqlConnectionStringBuilder(originalConnStr);
            builder.InitialCatalog = newCatalog;
            return builder.ConnectionString;
        }
        /// <summary>
        /// 连接到U8的系统库
        /// </summary>
        /// <returns></returns>
        public U8DataContext GetUfsystem()
        {
            var constr = ModifyCatalog(cHandleUF.cConnstr, "ufsystem");
            return new U8DataContext(constr);
        }
        /// <summary>
        /// 连接到U8的系统库
        /// </summary>
        /// <returns></returns>
        public U8DataContext GetUfData()
        {
            return new U8DataContext(cHandleUF.cConnstr);
        }
    }
}
